require(['./config'], () => {
    require(['template','Swiper','header','footer','floatbar'], (template,Swiper) => {
        class Index {
            constructor(){
                this.renderAcitivity()
                this.renderDream()
                this.renderGiftBox()
                this.renderBoutiqueCake()
                this.Swiper()
                this.renderTab()
                this.renderTabcontent()
            }
            // 主页主体内容
            // 梦蛋糕
            renderDream(){
                $.get('http://rap2api.taobao.org/app/mock/236205/index/renderdream', resp => {
                    if(resp.code === 200){
                        const {dreamCake,imgs} = resp.body
                        
                        var res = template('dreamcake-scr' , { dreamCake,imgs })
                        $('#dreamcake').html(res)
                    }
                })
            }
            // 元祖礼盒
            renderGiftBox(){
                $.get('http://rap2api.taobao.org/app/mock/236205/index/giftbox', resp => {
                    if(resp.code === 200){
                        const {giftBox,imgs} = resp.body
                        
                        var res = template('giftbox-scr' , { giftBox,imgs })
                        $('#giftbox').html(res)
                    }
                })
            }
            // 精品西点
            renderBoutiqueCake(){
                $.get('http://rap2api.taobao.org/app/mock/236205/index/boutique', resp => {
                    if(resp.code === 200){
                        const {BoutiqueCake,imgs} = resp.body
                        
                        var res = template('Boutiquecake-scr' , { BoutiqueCake,imgs })
                        $('#Boutiquecake').html(res)
                    }
                })
            }
            // 精彩活动
            renderAcitivity(){
                $.get('http://rap2api.taobao.org/app/mock/236205/index/activity', resp => {
                    if(resp.code === 200){
                        const {hotActive} = resp.body
                        var res = template('activeHot' , { hotActives : hotActive})
                        $('#imglist').html(res)
                    }
                })
            }
            // 轮播图
            Swiper(){
                var mySwiper = new Swiper ('#div1', {
                    direction: 'horizontal',
                    autoplay:{
                        disableOnInteraction:false,
                        waitForTransition: false,
                    },
                    speed: 2500,
                    delay: 2000,
                    loop: true,

                    pagination: {
                        el: '.swiper-pagination',
                        type: 'bullets',
                        dynamicBullets: true,
                        clickable:true,
                    },
                })    
            }
            // 选项卡
            renderTab(){
                $('.Tab1>#Tab1-li').on('mouseenter',function(){
                    $(this).addClass('change').siblings().removeClass('change')
                    $('.tab1-bottom>.tab1-bottom-ul').eq($(this).index()).addClass('change').siblings().removeClass('change')
                })
            }
            renderTabcontent(){
                $.get('http://rap2api.taobao.org/app/mock/236205/index/tabbar', resp => {
                    if(resp.code === 200){
                        const {tab1,tab2,tab3,tab4} = resp.body
                        var res = template('tab1-bottom-scr' , { tab1,tab2,tab3,tab4 })
                        
                        $('#tab1-bottom').html(res)
                        
                    }
                })
            }
        }
        new Index()
    })
})
